package com.pushway.demo.pojo;

import io.prometheus.client.Collector;
import io.prometheus.client.Counter;
import lombok.Getter;

import java.util.List;

/**
 * Counter：只增不减的计数器
 * @author chentiefeng
 */
@Getter
public class CounterPushItem extends PushItem {
    private String name;

    private String helpMsg;

    private List<String> labelNames;

    private Counter counter;
    protected CounterPushItem(String instance, String job) {
        super(instance, job);
    }
    public CounterPushItem(String instance, String job, String name, String helpMsg, List<String> labelNames) {
        this(instance, job);
        this.name = name;
        this.helpMsg = helpMsg;
        this.labelNames = labelNames;
        counter = Counter.build()
                .name(name)
                .help(helpMsg)
                .labelNames(this.labelNames.toArray(new String[0]))
                .register();
    }

    /**
     * 标记元素
     * @param labelValues
     * @return
     */
    public Counter.Child labels(String... labelValues) {
       return counter.labels(labelValues);
    }
    @Override
    public Collector getCollector() {
        return counter;
    }
}
